<?php echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"; ?>

<?php include("constants.inc") ?>
<?php include("classes.inc") ?>
<?php
    //header("Content-type: text/xml"); 

    mysql_connect(DB_SERVER, DB_USER, DB_PWD);

    mysql_select_db(DB_CATALOG);

    $result = mysql_query("SELECT distinct(ni.news_id), ni.title, ni.introImage, DATE_FORMAT(nh.news_date,'%a, %d %b %Y %T') AS date, 

        ni.intro, ni.message, u.username, u.function 

        FROM news_item AS ni join news_history AS nh on nh.news_id = ni.news_id

        join user u on nh.user_id = u.user_id 

        WHERE TO_DAYS(CURDATE()) - TO_DAYS(nh.news_date) <= 30

        ORDER BY ni.news_id DESC");



    $newsItems = array();

    while ($row = mysql_fetch_assoc($result)) {

        if (!isset($newsId) || $newsId != $row['news_id']) {

            $newsId = $row['news_id'];

            $newsItem = new NewsItem;

            $newsItem->news_id = $row['news_id'];

            $newsItem->title = $row['title'];

            $newsItem->date = $row['date']." ".date('O');

            $newsItem->intro = $row['intro'];

            $newsItem->introImage = $row['introImage'];

            $newsItem->message = $row['message'];

            $newsItem->username = $row['username'];

            $newsItem->function = $row['function'];

            if ( isValidURL($newsItem->introImage) ) {

                $newsItem->intro = "<table><tr valign=top><td><img src=".$newsItem->introImage." height=60 /></td><td>".$row['intro']."</td></tr></table>";
                                                       
            }

            array_push($newsItems, $newsItem);

        }

    }
    
    

?>



<rss version="2.0">

    <channel>

        <title>Schaakliga-Antwerpen.info</title>

        <link>http://www.schaakliga-antwerpen.info</link>

        <description>Welkom op de homesite van de Schaakliga Antwerpen. De liga zet zich in om het schaken in zijn provincie te promoten, en dit in goede samenwerking met de schaakclubs.</description>

        <language>nl</language>

<?

    foreach ($newsItems as $item) {

?>

        <item>

            <title><?=htmlspecialchars($item->title, ENT_NOQUOTES, "ISO-8859-1")?></title>

            <link><?=HOST?>/newsMessage.php?newsId=<?=$item->news_id?></link>

            <description><?=htmlspecialchars($item->intro, ENT_NOQUOTES, "ISO-8859-1")?></description>

            <pubDate><?=$item->date?></pubDate>

        </item>

<?   

    }

?>

    </channel>

</rss>